﻿using Quartz;
using System;

namespace ZYing.QPanel
{
    public static class JobHelper
    {
        private static void OnStatusFired(IJobExecutionContext context, string status)
        {
            var time = DateTimeOffset.UtcNow;
            if (context.Scheduler.Context.TryGetExecutionHistoryStore(out var store))
            {
                store.PushStatus(context.FireInstanceId, time, status);
            }
            if (StatusFired == null) return;
            var e = new StatusFiredEventArgs(context, time, status);
            StatusFired.Invoke(context.JobInstance, e);
        }

        public static event EventHandler<StatusFiredEventArgs> StatusFired;
        public static void FireStatus(IJobExecutionContext context, string status)
        {
            OnStatusFired(context, status);
        }
    }
}
